package com.yeyks.hotel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yeyks.hotel.dal.dao.HotelApplyMapper;
import com.yeyks.hotel.dal.domain.HotelApply;
import com.yeyks.hotel.param.HotelApplyListParam;
import com.yeyks.hotel.service.HotelApplyService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 酒店入住申请表 服务实现类
 *
 * @author shuai
 * @date 2019-06-28
 */
@Service
public class HotelApplyServiceImpl extends ServiceImpl<HotelApplyMapper, HotelApply> implements HotelApplyService {

    /**
     * 酒店申请列表查询
     *
     * @param param
     * @return
     */
    @Override
    public PageInfo<HotelApply> search(HotelApplyListParam param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        QueryWrapper<HotelApply> wrapper = new QueryWrapper<>();
        if (param.getKeyword() != null) {
            wrapper.like(HotelApply.HOTEL_NAME, param.getKeyword());
        }
        if (param.getArea() != null) {
            wrapper.like(HotelApply.HOTEL_AREA, param.getArea());
        }
        if (param.getStatus() != null) {
            wrapper.eq(HotelApply.STATUS, param.getStatus());
        } else {
            wrapper.ne(HotelApply.STATUS, HotelApply.Status.IGNORE.value());
        }
        wrapper.orderByDesc(HotelApply.CREATED_TIME);
        List<HotelApply> hotelApplies = baseMapper.selectList(wrapper);
        return new PageInfo<>(hotelApplies);
    }
}
